#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import logging.config

BASE_DIR = os.path.dirname(os.path.abspath(__file__))
DATA_DIR = os.path.join(BASE_DIR, 'data')
DOCUMENT_DIR = os.path.join(BASE_DIR, 'www')

LOG_FILE_PATH = os.path.join(BASE_DIR, 'logs', 'app.log')
LOG_HANDLERS = ['file']

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'simple': {
            'format': '[%(asctime)s] %(levelname)s [%(name)s] %(message)s'
        },
        'verbose': {
            'format': '[%(asctime)s] %(levelname)s [%(name)s:%(lineno)d] [%(request_id)s] "%(message)s"'
        },
    },
    'filters': {
        'request_id': {
            '()': 'utils.misc.logfilters.RequestIdFilter'
        }
    },
    'handlers': {
        'null': {
            'class': 'logging.NullHandler',
            'level': 'DEBUG'
        },
        'console': {
            'class': 'logging.StreamHandler',
            'level': 'DEBUG',
            'filters': ['request_id'],
            'formatter': 'simple'
        },
        'file': {
            'class': 'logging.handlers.WatchedFileHandler',
            'level': 'DEBUG',
            'filters': ['request_id'],
            'formatter': 'verbose',
            'filename': LOG_FILE_PATH,
            'encoding': 'utf-8'
        },
    },
    'loggers': {
        'appserver': {
            'handlers': LOG_HANDLERS,
            'level': 'DEBUG',
            'propagate': False
        },
        'api': {
            'handlers': LOG_HANDLERS,
            'level': 'DEBUG',
            'propagate': False
        },
        'utils': {
            'handlers': LOG_HANDLERS,
            'level': 'DEBUG',
            'propagate': False
        },
    },
    'root': {
        'handlers': ['null'],
        'level': 'DEBUG'
    },
}

logging.config.dictConfig(LOGGING)

# framework setting
REQUEST_ID_HEADER = 'X-Request-Id'
